package xyz.ddlnt.servicemg.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.model.dto.ExamQuestionDTO;
import xyz.ddlnt.model.dto.PublishStatus;
import xyz.ddlnt.model.vo.ExamQuestionInfoVO;
import xyz.ddlnt.model.vo.ExamQuestionVO;
import xyz.ddlnt.servicemg.service.ExamQuestionService;

import java.util.List;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/3 21:38
 */
@Slf4j
@RequestMapping("/exam_question")
@RestController
@RequiredArgsConstructor
public class ExamQuestionController {

    private final ExamQuestionService examQuestionService;

    /**
     * 添加试题
     * @param examQuestionDTO
     * @return
     */
    @PostMapping("/addExamQuestion")
    public Result<ExamQuestionVO> addExamQuestion(@RequestBody ExamQuestionDTO examQuestionDTO) {
        ExamQuestionVO examQuestionVO =examQuestionService.addExamQuestion(examQuestionDTO);
        return Result.success(examQuestionVO);
    }

    /**
     * 删除试题
     * @param id
     * @return
     */
    @DeleteMapping("/deleteExamQuestion")
    public Result<Boolean> deleteExamQuestion(@RequestParam Long id) {
        log.info("删除试题信息...");
        Boolean isDeleted =examQuestionService.deleteById(id);
        log.info("删除试题信息成功");
        return Result.success(isDeleted);
    }

    /**
     * 修改试题
     * @param examQuestionDTO
     * @return
     */
    @PutMapping("/updateExamQuestion")
    public Result<ExamQuestionVO> updateExamQuestion(@RequestBody ExamQuestionDTO examQuestionDTO) {
        ExamQuestionVO examQuestionVO = examQuestionService.updateExamQuestion(examQuestionDTO);
        return Result.success(examQuestionVO);
    }

    /**
     * 修改试题发布状态
     * @param publishStatus
     * @return
     */
    @PutMapping("/updatePublishStatus")
    public Result<Boolean> updatePublishStatus(@RequestBody PublishStatus publishStatus) {
        Boolean isUpdated =examQuestionService.updatePublishStatus(publishStatus);
        return Result.success(isUpdated);
    }

    /**
     * 根据试题id查询试题信息
     * @return
     */
    @GetMapping("/getExamQuestionById")
    public Result<ExamQuestionInfoVO> getExamQuestionById(@RequestParam Long id) {
        ExamQuestionInfoVO examQuestionVO = examQuestionService.getExamQuestionById(id);
        return Result.success(examQuestionVO);
    }

    /**
     * 查询所有试题信息
     * @return
     */
    @GetMapping("/getExamQuestions")
    public Result<List<ExamQuestionVO>> getExamQuestions() {
        List<ExamQuestionVO> examQuestionVOS = examQuestionService.listExamQuestionVO();
        log.info("查询结果为：{}",  examQuestionVOS);
        return Result.success(examQuestionVOS);
    }

}
